import {ProColumns} from "@ant-design/pro-table";

import {GenTableField} from "@/pages/system/tool/gen/add/interfaces";
import {Checkbox, InputNumber} from "antd";
import jdbcType from "@/utils/jdbcType";


// @ts-ignore
export const columns: ProColumns<GenTableField>[] = (javaFieldTypeList: any, setGenTableFieldList: React.Dispatch<React.SetStateAction<GenTableField[]>>): ProColumns<GenTableField>[] => {
  return [
    {
      title: "字段名",
      dataIndex: "name",
      align: "center",
      formItemProps: {
        rules: [
          {
            required: true,
            message: "字段名是必须的"
          }
        ]
      }
    },
    {
      title: "数据库类型",
      dataIndex: "type",
      align: "center",
      valueType: "select",
      valueEnum: jdbcType,
      formItemProps: {
        rules: [
          {
            required: true,
            message: "数据库类型是必须的"
          }
        ]
      }
    },
    {
      title: "java字段名",
      dataIndex: "javaName",
      align: "center",
      formItemProps: {
        rules: [
          {
            required: true,
            message: "数据库类型是必须的"
          }
        ]
      }
    },
    {
      title: "java字段类型",
      dataIndex: "javaType",
      align: "center",
      valueType: "select",
      valueEnum: javaFieldTypeList,
      formItemProps: {
        rules: [
          {
            required: true,
            message: "数据库类型是必须的"
          }
        ]
      }

    },
    {
      title: "长度",
      dataIndex: "length",
      align: "center",
      editable: false,
      render: (dom, entity, index, action, schema) => {
        return <InputNumber min={0} value={entity.length}
                            onChange={(value: any) => entity.length = value}></InputNumber>
      },

    },
    {
      title: "小数点",
      dataIndex: "point",
      align: "center",
      editable: false,
      render: (dom, entity, index, action, schema) => {
        return <InputNumber value={entity.point} min={0} onChange={(value: any) => entity.point = value}></InputNumber>
      },

    },
    {
      title: "默认值",
      dataIndex: "defaultValue",
      align: "center",
    },
    {
      title: "主键",
      dataIndex: "primary",
      align: "center",
      editable: false,
      valueType: "checkbox",
      render: (dom, entity, index, action, schema) => {
        return <Checkbox onChange={(event) => {
          entity.primary = event.target.checked
        }} name={"primary"}></Checkbox>
      },
    },
    {
      title: "自增",
      dataIndex: "auto",
      align: "center",
      editable: false,
      render: (dom, entity, index, action, schema) => {
        return <Checkbox onChange={(event) => {
          entity.auto = event.target.checked
        }} name={"primary"}></Checkbox>
      },
    },
    {
      title: "不为空",
      dataIndex: "notNull",
      align: "center",
      editable: false,
      render: (dom, entity, index, action, schema) => {
        return <Checkbox onChange={(event) => {
          entity.notNull = event.target.checked
        }} name={"primary"}></Checkbox>
      },
    },
    {
      title: "注释",
      dataIndex: "desc",
      align: "center"
    },
    {
      title: '操作',
      valueType: 'option',
      align: 'center',
      render: () => {
        return null;
      },
    },
  ]

}


